package com.brush.web.controller;

import com.brush.app.domain.req.Ad.add.AppAdvertiseAddReq;
import com.brush.app.domain.req.Ad.edit.AppAdEditReq;
import com.brush.app.domain.req.Ad.query.AppAdQueryReq;
import com.brush.app.domain.req.Subject.add.AppSubjectAddReq;
import com.brush.app.domain.req.Subject.edit.AppSubjectEditReq;
import com.brush.app.domain.req.Subject.query.AppSubjectQueryReq;
import com.brush.app.domain.resp.Ad.AppAdResp;
import com.brush.app.domain.resp.Subject.AppSubjectResp;
import com.brush.app.domain.resp.Subject.AppSubjectTreeResp;
import com.brush.app.service.AppSubjectService;
import com.brush.common.core.controller.BaseController;
import com.brush.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "后台-学科管理")
@RestController
@RequestMapping(value = "/admin/brush/subject")
public class AdminSubjectController extends BaseController {
    @Autowired
    private AppSubjectService appSubjectService;

    /*
    * 获取所有subject
    * */
    @PreAuthorize("@ss.hasPermi('app:subject:list')")
    @ApiOperation(value = "获取全部学科")
    @GetMapping("/data")
    public R<List<AppSubjectTreeResp>> allData(){
        List<AppSubjectTreeResp> allList =this.appSubjectService.getAllSubject();
        return R.ok(allList);
    }

    /*
    * 分页查询
    * */
    @PreAuthorize("@ss.hasPermi('app:subject:list')")
    @ApiOperation(value = "分页查询")
    @GetMapping("/list")
    public R<PageInfo<AppSubjectResp>> pagination(AppSubjectQueryReq req) {
        PageInfo<AppSubjectResp> page = this.appSubjectService.paginationQuery(req);
        return R.ok(page);
    }
    /*
    * 根据id查询
    * */
    @PreAuthorize("@ss.hasPermi('app:subject:query')")
    @ApiOperation(value = "根据id查询广告")
    @GetMapping("/{id}")
    public R<AppSubjectResp> findById(@PathVariable(value = "id") Long id) {
        AppSubjectResp resp = this.appSubjectService.findById(id);
        return R.ok(resp);
    }

    /*
    * 新增
    * */
    @PreAuthorize("@ss.hasPermi('app.subject.add')")
    @ApiOperation(value = "新增")
    @PostMapping
    public R add(@RequestBody @Valid AppSubjectAddReq req) {
        boolean res = this.appSubjectService.add(req);
        return super.isSuccess(res);
    }

    /*
    * 编辑修改
    * */
    @PreAuthorize("@ss.hasPermi('app:subject:edit')")
    @ApiOperation(value = "编辑")
    @PutMapping
    public R edit(@RequestBody @Valid AppSubjectEditReq req){
        boolean res =this.appSubjectService.edit(req);
        return super.isSuccess(res);
    }

    /*
     * 删除
     * */
    @PreAuthorize("@ss.hasPermi('app:subject:remove')")
    @ApiOperation(value = "删除")
    @DeleteMapping("/{ids}")
    public R delete(@PathVariable(value = "ids") Long[] ids){
        boolean res = this.appSubjectService.deleteById(ids);
        return super.isSuccess(res);
    }
}
